package com.example.shop_2302.adapter

import android.graphics.Color
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.CategoryEntityItem
import com.example.shop_2302.R

class OneAdapter:BaseQuickAdapter<CategoryEntityItem,BaseViewHolder>(R.layout.item_one) {
    var selectId = 515//默认选中第一个分类的id
    override fun convert(holder: BaseViewHolder, item: CategoryEntityItem) {
        holder.setText(R.id.one_tv,item.name)
        if(selectId==item.id){
            holder.getView<TextView>(R.id.one_tv).setTextColor(Color.BLUE)
            holder.getView<LinearLayout>(R.id.ll_one).setBackgroundResource(R.drawable.bg_cate_one)
        }else{
            holder.getView<TextView>(R.id.one_tv).setTextColor(Color.BLACK)
            holder.getView<LinearLayout>(R.id.ll_one).background = null//没有背景
        }
    }

    fun setId(id:Int){
        selectId = id
        notifyDataSetChanged()//让布局发生变化
    }
}